package cn.source.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.domain.PartyHeartfelt;
import cn.source.service.IPartyHeartfeltService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 心愿Controller
 *
 * @author sourcebyte.vip
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/system/heartfelt")
public class PartyHeartfeltController extends BaseController
{
    @Autowired
    private IPartyHeartfeltService partyHeartfeltService;

    /**
     * 查询心愿列表
     */
    @PreAuthorize("@ss.hasPermi('artcle:heartfelt:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartyHeartfelt partyHeartfelt)
    {
        startPage();
        List<PartyHeartfelt> list = partyHeartfeltService.selectPartyHeartfeltList(partyHeartfelt);
        return getDataTable(list);
    }

    /**
     * 获取心愿详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(partyHeartfeltService.selectPartyHeartfeltById(id));
    }

    /**
     * 新增心愿
     */
    @Log(title = "心愿", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartyHeartfelt partyHeartfelt)
    {
        return toAjax(partyHeartfeltService.insertPartyHeartfelt(partyHeartfelt));
    }

    /**
     * 修改心愿
     */
    @PreAuthorize("@ss.hasPermi('artcle:heartfelt:edit')")
    @Log(title = "心愿", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartyHeartfelt partyHeartfelt)
    {
        return toAjax(partyHeartfeltService.updatePartyHeartfelt(partyHeartfelt));
    }

    /**
     * 删除心愿
     */
    @PreAuthorize("@ss.hasPermi('artcle:heartfelt:remove')")
    @Log(title = "心愿", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(partyHeartfeltService.deletePartyHeartfeltByIds(ids));
    }

    /**
     * 导出心愿列表
     */
    @PreAuthorize("@ss.hasPermi('artcle:heartfelt:export')")
    @Log(title = "心愿", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartyHeartfelt partyHeartfelt)
    {
        List<PartyHeartfelt> list = partyHeartfeltService.selectPartyHeartfeltList(partyHeartfelt);
        ExcelUtil<PartyHeartfelt> util = new ExcelUtil<PartyHeartfelt>(PartyHeartfelt.class);
        util.exportExcel(response, list, "心愿数据");
    }
}
